
using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Entity;

namespace Data
{
	public class DARequisitosPlan
	{

        public static DataTable ListarRequisitosxPlan(string strCodPlanAdmision)
        {
            SqlDatabase sqlRequisitosxPlan = new SqlDatabase(Configuracion.GetConnection);
            DbCommand dbCmd = sqlRequisitosxPlan.GetStoredProcCommand("plst_RequisitosxPlan");
            sqlRequisitosxPlan.AddInParameter(dbCmd, "@strCodPlanAdmision", DbType.String, strCodPlanAdmision);
            return sqlRequisitosxPlan.ExecuteDataSet(dbCmd).Tables[0];
        }

        public static DataTable RegistrarRequisitosPlan(BERequisitosPlan oBERequisitosPlan)
        {
            SqlDatabase sql = new SqlDatabase(Configuracion.GetConnection);
            using (DbConnection connection = sql.CreateConnection())
            {
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();
                try
                {
                    DbCommand dbCmd = sql.GetStoredProcCommand("pmnt_RequisitosPlan");

                    sql.AddInParameter(dbCmd, "@CodPlanAdmision", DbType.String, oBERequisitosPlan.CodPlanAdmision);
                    sql.AddInParameter(dbCmd, "@CodRequisito", DbType.String, oBERequisitosPlan.CodRequisito);
                    sql.AddInParameter(dbCmd, "@Estado", DbType.Int16, oBERequisitosPlan.Estado);
                    sql.AddInParameter(dbCmd, "@UsuCreacion", DbType.String, oBERequisitosPlan.UsuCreacion);
                    sql.AddInParameter(dbCmd, "@UsuModificacion", DbType.String, oBERequisitosPlan.UsuModificacion);
                    DataTable dtRequisitosPlan = sql.ExecuteDataSet(dbCmd).Tables[0];
                    transaction.Commit();
                    return dtRequisitosPlan;
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
            }
        }
    }
}
      